<template>
  <el-card>
    <el-form :inline="true">
      <el-form-item label="一级分类" style="width: 300px">
        <el-select :disabled="scene==0?false:true" v-model=" CategoryStore.c1Id" @change="handler">
          <!-- label:即为展示数据 value即为select下拉菜单收集的数据-->
          <el-option v-for="(c1,index) in  CategoryStore.c1Arr" :key="c1.id" :label="c1.name" :value="c1.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类" style="width: 300px">
        <el-select :disabled="scene==0?false:true" v-model="CategoryStore.c2Id" @change="handler1">
          <el-option v-for="(c2,index) in CategoryStore.c2Arr" :key="c2.id" :label="c2.name" :value="c2.id"></el-option>
      
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类" style="width: 300px">
        <el-select :disabled="scene==0?false:true" v-model="CategoryStore.c3Id">
          <el-option v-for="(c3,index) in CategoryStore.c3Arr" :key="c3.id" :label="c3.name" :value="c3.id"></el-option>
       
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup lang="ts" name="Category">
import { onMounted } from 'vue';
import useCategoryStore from '@/store/modules/category';

let CategoryStore = useCategoryStore();
onMounted(()=>{
   getC1()
});

const getC1=()=>{
   CategoryStore.getC1()
}
//此方法即为一级分类下拉菜单的change事件（选中值的时候才会触发，保证一级分类Id有了）
const handler=()=>{
  //需要将二级和三级分类的数据清除
  CategoryStore.c2Id='',
  CategoryStore.c3Arr=[],
  CategoryStore.c3Id=''
   //通知仓库获取二级分类的数据
   CategoryStore.getC2();
}
//此方法即为二级分类下拉菜单的change事件（选中值的时候才会触发，保证二级分类Id有了）
const handler1=()=>{
  
  CategoryStore.c3Id=''
  CategoryStore.getC3();
}
//接收父组件传递过来的scene
defineProps(['scene'])
</script>

<style lang="scss" scoped></style>
